package it.low.game.client.gui.graphics;

import it.low.game.client.GameClient;
import it.low.game.client.gui.panel.GameBoardPanel;
import it.low.game.core.element.State;
import it.low.game.core.location.MapPoint;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;

import javax.swing.ImageIcon;

public class GraphicElement {
	
	protected State state = null;
	protected Image image = null;
	protected int height = 0;
	
	protected int shadowWidth = 0;
	protected int shadowHeight = 0;
	
	public void setState(State state){
		this.state = state;
	}
	
	public void initGraphic(ImageIcon imageIcon){
		this.image = imageIcon.getImage();
		this.height = imageIcon.getIconHeight();
		
		shadowWidth = imageIcon.getIconWidth();
		shadowHeight = shadowWidth/3;
	}

	public void draw(Graphics g){
		MapPoint mapPosition = state.getMapPosition();
		Point gamePanelPoint = GameClient.getGameSession().getGamePanelRelativePoint(mapPosition);
		Point screenPoint = GameBoardPanel.getScreenRelativePoint(gamePanelPoint);
		
		g.drawOval(screenPoint.x-shadowWidth/2, screenPoint.y-shadowHeight, shadowWidth, shadowHeight);
		
		g.drawImage(image, screenPoint.x-shadowWidth/2, screenPoint.y-height, null);	
		//g.drawString(element.getElementName(), screenPoint.x-shadowWidth/2, screenPoint.y-height-10);
	}
	
}
